﻿using System.Collections.Generic;
using System.Xml.Linq;
using Harvest.API.Model;

namespace Harvest.API
{

	public partial class Wrapper
	{

        /// <summary>
        /// Get all tasks.
        /// </summary>
        /// <remarks>GET /tasks</remarks>
        /// <returns></returns>
        public List<Task> GetTasks()
        {
            var data = Request(WebRequestMethodEnum.Get, "tasks");
            var xDocument = XDocument.Parse(data);
            return xDocument.ToTasks();
        }

        /// <summary>
        /// Get an existing task.
        /// </summary>
        /// <remarks>GET /tasks/#{task_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public Task GetTask(int id)
        {
            var data = Request(WebRequestMethodEnum.Get, "tasks/" + id);
            var xDocument = XDocument.Parse(data);
            return xDocument.ToTask();
        }

        /// <summary>
        /// Delete an existing task.
        /// </summary>
        /// <remarks>DELETE /tasks/#{task_id}</remarks>
        /// <param name="id"></param>
        /// <returns></returns>
        public string DeleteTask(int id)
        {
            var data = Request(WebRequestMethodEnum.Delete, "tasks/" + id);
            return data;
        }

        /// <summary>
        /// Update an existing task.
        /// </summary>
        /// <remarks>PUT /task/#{task_id}</remarks>
        /// <param name="task"></param>
        /// <returns></returns>
        public string UpdateTask(Task task)
        {
            var data = Request(WebRequestMethodEnum.Put, "tasks/" + task.Id, task.Serialize());
            return data;
        }

        /// <summary>
        /// Create a new task.
        /// </summary>
        /// <remarks>POST /tasks</remarks>
        /// <param name="task"></param>
        /// <returns></returns>
        public string CreateTask(Task task)
        {
            var data = Request(WebRequestMethodEnum.Post, "tasks", task.Serialize());
            return data;
        }

	}

}
